package com.cloudsigns.factorymanager2.project.presenter;

import com.cloudsigns.factorymanager2.project.iview.IAddEngineeringInstallationOrderView;
import com.cloudsigns.factorymanager2.project.iview.IAddMaintenanceOrderView;
import com.cloudsigns.factorymanager2.project.model.AddEngineeringInstallationOrderModel;
import com.cloudsigns.factorymanager2.project.model.AddMaintenanceOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddEngineeringInstallationOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddMaintenaceOrderModel;

/**
 * Created by tony on 2018/3/21.
 */

public class AddMaintenanceOrderPresenter {
    private IAddMaintenanceOrderView view;
    private IAddMaintenaceOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public AddMaintenanceOrderPresenter(IAddMaintenanceOrderView view) {
        this.view = view;
        this.model = new AddMaintenanceOrderModel();
    }

    public void addEngineeringMaintenancenOrder() {

        model.addEngineeringMaintenanceOrder(view.getCategory(), view.getContent(), view.getEngineeringName(), view.getLat(), view.getLon(), view.getProjectName(), view.getQuestionDesc(), new AddMaintenanceOrderModel.OnAddMaintenanceOrderListener() {

            @Override
            public void success(final String projectId) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addMaintenanceOrderSuccess(projectId);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });

    }
}
